import { SSE } from "sse.js";
import * as R from "ramda";

const connect = R.curryN(6, _connect);

function _connect(url, headers, data, method, onMessage, onError) {
  let sse;
  sse = new SSE(url, { headers }, data, method);
  sse.addEventListener("message", onMessage);
  sse.addEventListener("error", onError);

  return sse;
}

function createSSE(onMessage = R.identity, onError = R.identity) {
  return connect(R.__, R.__, R.__, R.__, onMessage, onError);
}
export default createSSE;
